﻿using System;
using BG.Data;

namespace BG.Service
{
    public partial class Card
    {

        public static int WriteCard(TCard t)
        {
            object[] obj = new object[] { t.Port, t.EndDate, t.CardNo, t.BuildNo, t.FloorNo, t.RoomNo, t.Memo };
            System.Type oType = System.Type.GetTypeFromProgID("IssueTCrd.DigiCard");
            object o = System.Activator.CreateInstance(oType);
            int s = Convert.ToInt32(oType.InvokeMember("WriteCard", System.Reflection.BindingFlags.InvokeMethod, null, o, obj));
            return s;
        }

        public static TCard ReadCard(TCard t,out int s)
        {
            object[] obj = new object[] { t.Port, t.CardNo, t.RoomNo, t.EndDate };
            System.Type oType = System.Type.GetTypeFromProgID("IssueTCrd.DigiCard");
            object o = System.Activator.CreateInstance(oType);
            s = Convert.ToInt32(oType.InvokeMember("ReadCard", System.Reflection.BindingFlags.InvokeMethod, null, o, obj));
            return t;
        }

        public static string ErrMessage(int i)
        {
            string str = string.Empty;
            switch (i)
            {
                case -99: str = "端口错误"; break;
                case -128: str = "读卡错误"; break;
                case -129: str = "写卡错误"; break;
                case -300:
                case -310: str = "卡片不符合门锁标准"; break;
                case -410: str = "需要到发卡系统发卡输入授权号"; break;
                case -500: str = "复位卡，不能用作发卡"; break;
                case -600: str = "特别IC卡，不能用作发卡"; break;
                case -700: str = "不是宾客卡"; break;
                case -800: str = "找不到 Setting.INI"; break;
                case -810: str = "不能打开 Setting.INI"; break;
                case -811: str = "lyComm.dll文件丢失。解决:将lyComm.dll拷贝到DLL的所在目录下。"; break;
                case -812: str = "Mwic_32.dll文件丢失。解决:将Mwic_32.dll 拷贝到DLL的所在目录下。"; break;
                case -820:
                case -830: str = "数据库路径错误。解决:修改Setting的数据库路径。"; break;
                case -840: str = "打开数据库错误"; break;
                case -850: str = "更新数据库错误"; break;
                case -851: str = "入住日期格式错误(YYYYMMDDhhmm)"; break;
                case -852: str = "有效日期格式错误(YYYYMMDDhhmm)，日期必须不小于入住日期"; break;
                case -853: str = "卡号格式错误，(8位数字字符)"; break;
                case -854: str = "楼号格式错误，(1-99)"; break;
                case -855: str = "层号格式错误，(1-99)"; break;
                case -856: str = "房号格式错误，(4位数字字符)"; break;
            }
            return str;
        }
    }
}
